package org.lex.ftp.util;

import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Resource {
	static {
		c = Resource.class;
		iconCache = new ConcurrentHashMap<String, Icon>(20);
	}
	private static final String BasePath = "/lex/ftp/resources/";
	private static final String IconPath = BasePath + "images/";
	private static final String SoundPath = BasePath + "sound/";
	// =========================================================
	public static final String GlobalSound = "global.wav";
	// =========================================================
	public static final String DeleteIcon = "delete.png";
	public static final String TreeIcon = "tree.png";
	public static final String GoUpIcon = "up.png";
	public static final String RefreshIcon = "refresh.png";
	// ===============================================================
	public static final String DownloadGreenIcon = "download.green.png";
	public static final String DownloadRedIcon = "download.red.png";
	public static final String UploadGreenIcon = "upload.green.png";
	public static final String UploadRedIcon = "upload.red.png";
	// ==========================================================
	public static final String NormalCloseIcon = "close.normal.png";
	public static final String PressedCloseIcon = "close.pressed.png";
	public static final String RolloverCloseIcon = "close.rollover.png";
	// =============================================================
	public static final String FileIcon = "file.png";
	public static final String FolderIcon = "folder.png";

	private static final Class<Resource> c;
	private static final Map<String, Icon> iconCache;

	private Resource() {
	}

	public static Icon getIcon(String key) {
		Icon icon = null;
		if (false == iconCache.containsKey(key)) {
			icon = new ImageIcon(getURL(IconPath + key));
			iconCache.put(key, icon);
		} else {
			icon = iconCache.get(key);
		}
		return icon;
	}

	public static URL getSound(String key) {
		return getURL(SoundPath + key);
	}

	public static URL getURL(String key) {
		return c.getResource(key);
	}
}
